<template>
    <h1>修改页面</h1>
<table>
    <tr>
        <td>理财项目名称</td>
        <td><input type="text" v-model="info.F_Name"></td>
    </tr>
    <tr>
        <td>年收益</td>
        <td><input type="text" v-model="info.F_ARY"></td>
    </tr>
    <tr>
        <td>最低金额</td>
        <td><input type="text" v-model="info.F_MinMoney"></td>
    </tr>
    <tr>
        <td>风险等级</td>
        <td><input type="radio" name="Flevel" value="0" checked>低风险
        <input type="radio" name="Flevel" value="1">中风险
        <input type="radio" name="Flevel" value="2">高风险
        
        </td>
    </tr>
    <tr>
        <td>理财利率</td>
        <td>
            <select name="" id="" v-model="info.I_Id">
                <option value="0">--请选择--</option>
                <option v-for="i in InterestInfo" :value="i.I_Id">{{ i.I_Year }}年利率为{{ i.I_Interest }}%</option>
            </select>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <button @click="UpdateFinan" class="btn btn-success" >保存</button>
        </td>
    </tr>
</table>
</template>
<script setup lang="ts">
import {useRoute,useRouter} from 'vue-router'
import axios from 'axios'
import {onMounted,ref} from 'vue'
const route=useRoute()
const router=useRouter()
var Fid=route.query.Fid
const InterestInfo=ref([{
    I_Id:0,
    I_Interest:0,
    I_Year:0
}])
onMounted(()=>{
    LoadInterest()
    SelectById()
})
//完成基本理财信息加载
const LoadInterest=()=>{
    axios.get("https://localhost:44358/api/Finan/ShowInterest",{
       
    }).then(res=>{
        InterestInfo.value=res.data
    }).catch(err=>{
        console.log(err);
    })
}
const info=ref({
    F_Name:'',
    F_ARY:'',
    F_MinMoney:'',
    F_Number:'',
    F_Level:0,
    I_Id:0,
    F_Id:Fid
});
const SelectById=()=>{
    axios.get('https://localhost:44358/api/Finan/SelectById',
        {
            params:{
                Fid:Fid
            }
        }
    ).then(res=>{
        info.value.F_ARY=res.data.F_ARY
        info.value.F_Level=res.data.F_Level
        info.value.F_MinMoney=res.data.F_MinMoney
        info.value.F_Name=res.data.F_Name
        info.value.I_Id=res.data.I_Id
    }).catch(err=>{
        console.log(err);
        }
    )
}
const UpdateFinan=()=>{
    axios.post('https://localhost:44358/api/Finan/UpdateById',
        {
            F_Id:info.value.F_Id,
            F_Name:info.value.F_Name,
            F_ARY:info.value.F_ARY,
            F_MinMoney:info.value.F_MinMoney,
            F_Level:info.value.F_Level,
            I_Id:info.value.I_Id
        }
    ).then(res=>{
        if(res.data==-1){
            alert("有人投资，修改失败")
            return
        }else if(res.data>0){
            alert("修改成功")
            router.push(
                {
                    path:'ShowFinanInfo'
                }
            )
        }else{
            alert("修改失败")
        }
    }).catch(err=>{
        console.log(err);
    })
}
</script>